package com.itheima.config;

import com.itheima.interceptor.MyInterceptor;
import com.itheima.interceptor.MyInterceptor1;
import com.itheima.interceptor.MyInterceptor2;
import com.itheima.pojo.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MvcConfig implements WebMvcConfigurer {


    /**o到spring  ioc容器中
     */
    @Bean
    public MyInterceptor myInterceptor(){
        return new MyInterceptor();
    }

    @Bean
    public MyInterceptor1 myInterceptor1(){
        return new MyInterceptor1();
    }

    @Bean
    public MyInterceptor2 myInterceptor2(){
//        User u = User.builder().id().age().name().password()
        return new MyInterceptor2();
    }
    /**
     * 重写该方法:往拦截器链添加自定义拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//       通过registry添加myInterceptor拦截器,并设置路径为/*
        registry.addInterceptor(myInterceptor()).addPathPatterns("/*");
        registry.addInterceptor(myInterceptor1()).addPathPatterns("/*");
        registry.addInterceptor(myInterceptor2()).addPathPatterns("/*");
    }

}
